package com.lhl.security.jwt.config;

import io.swagger.annotations.Api;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @className: com.lhl.security.jwt.config.JWTAuthenticationEntryPoint
 * @description: TODO 类描述
 * @author: king
 * @date: 2020-11-09
 **/
@Api(tags = "JWTAuthenticationEntryPoint", produces = "")
public class JWTAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/javascript;charset=utf-8");
//        response.getWriter().print(JSONObject.toJSONString(RestMsg.error("没有访问权限!")));
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    }
}
